package cn.chainco.cts.action;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;

import cn.chainco.cts.iservice.CommonManager;
import cn.chainco.cts.iservice.IExcRateManager;
import cn.chainco.cts.iservice.IVerificationManager;
import cn.chainco.cts.iservice.IWorkManager;
import cn.chainco.cts.jdo.Company;
import cn.chainco.cts.jdo.Currency;
import cn.chainco.cts.jdo.Employee;
import cn.chainco.cts.jdo.ExcRate;
import cn.chainco.cts.jdo.User;
import cn.chainco.cts.jdo.Verification;
import cn.chainco.cts.jdo.VerificationBill;
import cn.chainco.cts.jdo.VerificationTeam;
import cn.chainco.cts.jdo.WorkFee;
import cn.chainco.cts.jdo.WorkTeam;
import cn.chainco.cts.utils.CommUtils;
import cn.chainco.cts.utils.CookieUtil;
import cn.chainco.cts.utils.query.OP;
import cn.chainco.cts.utils.query.QueryOrder;
import cn.chainco.cts.utils.query.QueryParam;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("unchecked")
@InterceptorRef("ctsInterceptors")
public class AccountAction extends ActionSupport {
	private static final long serialVersionUID = 1L;

	private Verification verification;

	private List<Verification> verificationList;

	private IVerificationManager verificationManager;

	private IExcRateManager excRateManager;

	private CommonManager commonManager;

	private List<VerificationBill> billList;

	private VerificationBill verificationBill;

	private IWorkManager workManager;
	
	private int pageSize = 15;

	private int pageNumber = 1;

	/**
	 * 财务内容的列表
	 * 
	 * @return
	 */
	@Action("financiallist")
	public String financiallist() {
		return "account/financiallist";
	}

	/**
	 * 结算成员
	 * 
	 * @return
	 */
	@Action("teamlist")
	public String teamlist() {
		HttpServletRequest request = ServletActionContext.getRequest();
		String employeeId = CookieUtil.getCookieValue(request,"cts_employeecpyid");
		request.setAttribute("financialtype", request.getParameter("financialtype"));
		if (CommUtils.isCorrectNumber(employeeId)) {
			Employee em = this.commonManager.findEntityByPK(Employee.class,
					Long.valueOf(employeeId));
			request.setAttribute("employee2", em);
		}

		return "account/settlementteam";
	}

	/**
	 * 查找公司下有财务权限的员工
	 * 
	 */
	@Action("findLostManlist")
	public void findLostManlist() {
		HttpServletRequest request = ServletActionContext.getRequest();
		String listId = request.getParameter("listId");
		String companyId = CookieUtil.getCookieValue(request, "cts_emplcpyid");
		String userName = CookieUtil.getCookieValue(request, "cts_username");
		String name = request.getParameter("name");

		String json = "[]";
		if (CommUtils.isCorrectNumber(companyId)) {
			String sql = " 1=1 and status=1 and companyId=" + companyId;
			sql += " and type=0 ";
					//+ " and (auth2=1 or auth7=1 or auth8=1 or auth9=1)";
			if (listId != null && !"".equals(listId) && !"0".equals(listId)) {
				sql += " and id not in (" + listId + ")";
			}

			sql += " and nickname like '%" + name + "%'";

			List<Employee> emlist = ActionUtil.findListByE(Employee.class, sql);
			if (emlist.size() > 0) {
				json = "";
				for (int i = 0; i < emlist.size(); i++) {
					Employee _em = emlist.get(i);
					json += "{'userId':'" + _em.getId() + "','userName':'"
							+ _em.getNickname() + "'},";
				}

				/**
				 * String userIdlist = ""; for(int i=0;i<emlist.size();i++){
				 * userIdlist += emlist.get(i).getUser().getId(); if(i<
				 * emlist.size() -1){ userIdlist +=","; } }
				 * 
				 * sql = " id in ("+userIdlist+") and userName like
				 * '%"+name+"%'"; List<User> userlist =
				 * ActionUtil.findListByE(User.class, sql); json = "";
				 * 
				 * for (User user : userlist) { if(user.getStatus()!=2 &&
				 * !user.getUserName().equals(userName) &&
				 * !user.getUserName().equals(VarData.adminName)){ json +=
				 * "{'userId':'"+user.getId()+"','userName':'"+user.getUserName()+"'},"; } }
				 */

				if (json.trim().length() > 0) {
					json = json.substring(0, json.length() - 1);
				}
				json = "[" + json + "]";
			}
		}

		ActionUtil.outputData(json);
	}

	/**
	 * 提取结算成员
	 * 
	 * @param request
	 * @param verification
	 * @return
	 */
	public List<VerificationTeam> getSetVerification(
	    HttpServletRequest request, Verification verification) {
		String teamStr = request.getParameter("teamData");

		List<VerificationTeam> list = new ArrayList<VerificationTeam>();

		if (teamStr != null && !"".equals(teamStr)) {
			String[] teamAry = teamStr.split(";");
			for (String string : teamAry) {
				String[] teamAry2 = string.trim().split(",");
				Long id = Long.valueOf(teamAry2[0]);
				Integer auth = Integer.valueOf(teamAry2[1]);

				Employee me = this.commonManager.findEntityByPK(Employee.class, id);
//				me.setId(id);

				VerificationTeam vt = new VerificationTeam();
				if (verification != null) {
					vt.setVerification(verification);
				}

				vt.setAuth(auth);
				vt.setEmployee(me);

				list.add(vt);
			}
		}

		return list;

	}

	/***************************************************************************
	 * 核销列表
	 */
	@Action("searchVerification")
	public String searchVerification() {
		HttpServletRequest request = ServletActionContext.getRequest();
		String isContentFlag = request.getParameter("isContentFlag");
		String userId = CookieUtil.getCookieValue(request, "cts_userid");

		User user = this.commonManager.findEntityByPK(User.class, Long.parseLong(userId));
		String cts_employeecpyid = CookieUtil.getCookieValue(request,"cts_employeecpyid");
		Employee e = this.commonManager.findEntityByPK(Employee.class, Long.parseLong(cts_employeecpyid));
		Company company = e.getCompany();
		request.setAttribute("e", e);
		if (isContentFlag == null) {
			ActionUtil.getTopAllInfo();
			return "account/financialparent";
		}
		String keyword = request.getParameter("keyword");
		if (keyword.equals(this.getText("cts.account.searchDefault"))) {
			keyword = null;
		}
		String type = request.getParameter("type");
		String dateType = request.getParameter("dateType");

		int inttype = 999;
		int intdateType = 999;
		if (type != null) {
			inttype = Integer.parseInt(type);
		}
		if (dateType != null) {
			intdateType = Integer.parseInt(dateType);
		}
		List<Verification> list = this.verificationManager.getVerificationByConditon(company, e, user, keyword,intdateType, inttype, pageSize , pageNumber);
		request.setAttribute("list", list);

		/** ***************************合计代码********************** */
		// 汇兑损益
		List<Object> list1 = this.verificationManager.getExchangeMoneyByCompany(company);
		List<Map<String, Float>> totalLoss = changeList(list1);
		request.setAttribute("totalLoss", totalLoss);

		// 合计
		List<Object> list2 = this.verificationManager.getMoneyByCompany(company,e, 0);//收款
		List<Object> list3 = this.verificationManager.getMoneyByCompany(company,e, 1);//付款
		List<Object> list4 = this.verificationManager.getMoneyByCompany(company,e, 2);//奖励
		List<Map<String, Float>> allTotallist1 = changeList(list2);
		List<Map<String, Float>> allTotallist2 = changeList(list3);
		List<Map<String, Float>> allTotallist3 = changeList(list4);
		request.setAttribute("allTotallist1", allTotallist1);// 收入
		request.setAttribute("allTotallist2", allTotallist2);// 支出
		request.setAttribute("allTotallist3", allTotallist3);// 奖励

		// 银行手续费
		List<Object> list5 = this.verificationManager.getExchangeBlankMoneyByCompany(company,e);
		List<Map<String, Float>> totalFee = changeList(list5);
		request.setAttribute("totalFee", totalFee);
		int pageCount =  this.verificationManager.getCountVerificationByConditon(company, e, user, keyword, intdateType, inttype);
		int _pageCoount = 0;
		if(pageCount <=15 ){
			_pageCoount = 1;
	    }else if(pageCount % 15 == 0){
	    	_pageCoount = (pageCount / 15);
	    }else{
	    	_pageCoount = (pageCount / 15 + 1);
	    }
		request.setAttribute("pageCount", _pageCoount );
		return "account/financiallist";
	}

	/**
	 * List<Object>转换
	 */
	private List<Map<String, Float>> changeList(List<Object> listObj) {
		List<Map<String, Float>> list = new ArrayList<Map<String, Float>>();
		for (int i = 0; i < listObj.size(); i++) {
			Object[] obj = (Object[]) listObj.get(i);
			Map<String, Float> map = new HashMap<String, Float>();
			map.put(obj[0].toString(), Float.parseFloat(obj[1].toString()));
			list.add(map);
		}
		return list;
	}

	/**
	 * 获取结算单状态数目
	 */
	@Action("getCountVerificationByType")
	public void getCountVerificationByType() {
		String result = "";
		try {
			HttpServletRequest request = ServletActionContext.getRequest();
			String userId = CookieUtil.getCookieValue(request, "cts_userid");
			User user = this.commonManager.findEntityByPK(User.class, Long
					.parseLong(userId));
			String cts_employeecpyid = CookieUtil.getCookieValue(request,
					"cts_employeecpyid");
			Employee e = this.commonManager.findEntityByPK(Employee.class, Long
					.parseLong(cts_employeecpyid));
			Company company = e.getCompany();
			int s1 = this.verificationManager
					.getCountByStatus(company, user,e, 0);
			int s2 = this.verificationManager
					.getCountByStatus(company, user,e, 1);
			int s3 = this.verificationManager
					.getCountByStatus(company, user,e, 2);
			result += s1 + "," + s2 + "," + s3 + ",";
		} catch (Exception e) {
			e.printStackTrace();
		}
		ActionUtil.outputData(result);
	}
	
	//进入付款核销的详情
	@Action("payDetail")
	public String payDetail() {
		HttpServletRequest request = ServletActionContext.getRequest();
		List<Currency> currencys = ActionUtil.getCompanyParam(null, 0, 0, 0,null);
		request.setAttribute("currencys", currencys);
		Employee employee = ActionUtil.getSelectEmployee();

		String idStr=request.getParameter("id");
		if(idStr==null || "".equals("idStr")){
			idStr="0";
		}
		
		verification=this.commonManager.findEntityByPK(Verification.class, Long.parseLong(idStr));
		
		if(verification!=null){
			//浏览状态
			List<QueryParam> paramList = new ArrayList<QueryParam>();
			QueryParam param = new QueryParam();
			param.setField(" verificationId = "+verification.getId());
			param.setOp(OP.sql);
			param.setValue(new Object[]{});
			paramList.add(param);
			
			List<QueryOrder> orderList=new ArrayList<QueryOrder>();
			QueryOrder order=new QueryOrder();
			order.setField("id");
			order.setAscOrder(true);
			orderList.add(order);
			
			List<VerificationTeam> vtlist=this.commonManager.findByCustomized(VerificationTeam.class,paramList, orderList);
			
			//控制权限
			String cts_employeecpyid = CookieUtil.getCookieValue(request, "cts_employeecpyid");
			String userId = CookieUtil.getCookieValue(request, "cts_userid");
			if(cts_employeecpyid==null || "".equals(cts_employeecpyid)){
				request.setAttribute("msg", "抱歉!您没有权限查看该订单!");
				return "work/noWorkDetail";
			}
			Employee emp=this.commonManager.findEntityByPK(Employee.class, Long.parseLong(cts_employeecpyid));
			//如果是访客，但不是自己相关的单没有权限查看
			if(emp!=null && emp.getType()==1){
				if(emp.getId()!=verification.getEmployee().getId()){
					request.setAttribute("msg", "抱歉!您没有权限查看该订单!");
					return "work/noWorkDetail";
				}
			}else{
				List<Employee> empList=new ArrayList<Employee>();
				for (VerificationTeam team : vtlist) {
					empList.add(team.getEmployee());
				}
				//没有在作业团队里面，或者不是该订单所属公司的管理员都没有权限查看
				if(!empList.contains(emp) && verification.getCompany().getUser().getId()!=Long.parseLong(userId)){
					request.setAttribute("msg", "抱歉!您没有权限查看该订单!");
					return "work/noWorkDetail";
				}
			}
			request.setAttribute("vtlist", vtlist);
			
			// 已结算明细
			billList = this.verificationManager.getVerificationBillByParent(verification.getId());
			float writtenOfmoney = verification.getMoney()- verification.getNotWrittenOffmoney();

			float mPercent = writtenOfmoney / verification.getMoney();
			if (mPercent < 0) {
				mPercent = 0;
			} else if (mPercent > 1) {
				mPercent = 1;
			}
			BigDecimal b = new BigDecimal(mPercent);
			mPercent = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
			request.setAttribute("percent", mPercent);// 计算用的百分比（如0.85）
			request.setAttribute("writtenOfmoney", writtenOfmoney);
			// 给前台提供所有币种对人民币的汇率
			Map<Currency, Float> map = this.excRateManager
					.getAllCurrencyToRMB();
			StringBuilder sb = new StringBuilder();
			for (Map.Entry<Currency, Float> entry : map.entrySet()) {
				sb
						.append(entry.getKey().getId() + "," + entry.getValue()
								+ ";");
			}
			request.setAttribute("allCurrencyToRMB", CommUtils
					.deleteLastChar(sb.toString()));
			
			int authType=-1;
			//如果不是访客
			if(vtlist!=null && emp.getType()!=1){
				for (VerificationTeam team : vtlist) {
					if(team.getEmployee().getUser().getId()==Long.parseLong(userId)){
						authType=team.getAuth();
						break;
					}
				}
			}
			//如果管理员的公司员工创建的订单，管理员也有权限操作该订单
			if(verification.getCompany().getUser().getId()==Long.parseLong(userId)){
				authType=1;
			}
			request.setAttribute("authType", authType);
			request.setAttribute("emp", emp);
		} else {
			// 新增状态
			verification = new Verification();
			List<VerificationTeam> vtlist = this.getSetVerification(request,
					null);
			if(vtlist==null || vtlist.size()==0){
				request.setAttribute("msg", "该订单不存在！");
				return "work/noWorkDetail";
			}
			
			request.setAttribute("vtlist", vtlist);
			request.setAttribute("teamData", request.getParameter("teamData"));
			request.setAttribute("newCardNum", this.verificationManager
					.getNewCardNum(employee.getCompany(), 1));
		}

		return "account/payDetail";
	}

	//查询付款核销可以结算的款项
	@Action("payDetailFee")
	public String payDetailFee() {
		HttpServletRequest request = ServletActionContext.getRequest();
		List<WorkFee> workFeeList = new ArrayList<WorkFee>();
		Employee employee = new Employee();
		String workCode = request.getParameter("workCode");
		String personId = request.getParameter("personId");
		if (CommUtils.isCorrectInt(personId)) {
			employee = this.commonManager.findEntityByPK(Employee.class, Long
					.parseLong(personId));
		}
		// 应付
		String type3 = request.getParameter("type3");
		if (type3 != null && "" != type3) {
			List<WorkFee> workFeeList3 = verificationManager
					.getWorkFeeByCondition(employee.getCompany(), employee,
							Integer.parseInt(type3), workCode,null);
			if (workFeeList3 != null && workFeeList3.size() > 0) {
				workFeeList.addAll(workFeeList3);
			}
		}
		// 代付
		String type4 = request.getParameter("type4");
		if (type4 != null && "" != type4) {
			List<WorkFee> workFeeList4 = verificationManager
					.getWorkFeeByCondition(employee.getCompany(), employee,
							Integer.parseInt(type4), workCode,null);
			if (workFeeList4 != null && workFeeList4.size() > 0) {
				workFeeList.addAll(workFeeList4);
			}
		}
		// 应收
		String type1 = request.getParameter("type1");
		if (type1 != null && "" != type1) {
			List<WorkFee> workFeeList1 = verificationManager
					.getWorkFeeByCondition(employee.getCompany(), employee,
							Integer.parseInt(type1), workCode,null);
			if (workFeeList1 != null && workFeeList1.size() > 0) {
				workFeeList.addAll(workFeeList1);
			}
		}
		// 代收
		String type2 = request.getParameter("type2");
		if (type2 != null && "" != type2) {
			List<WorkFee> workFeeList2 = verificationManager
					.getWorkFeeByCondition(employee.getCompany(), employee,
							Integer.parseInt(type2), workCode,null);
			if (workFeeList2 != null && workFeeList2.size() > 0) {
				workFeeList.addAll(workFeeList2);
			}
		}
		request.setAttribute("workFeeList", workFeeList);
		return "account/payDetailFee";
	}

	//新增或修改付款核销
	@Action("saveOrEditPayVerification")
	public void saveOrEditPayVerification(){
		HttpServletRequest request = ServletActionContext.getRequest();
		Employee employee = ActionUtil.getSelectEmployee();
		String currency = request.getParameter("verification_currency");
		verification.setMoney(verification.getToAccountMoney()
				- verification.getBankDeductionMoney());
		if (CommUtils.isCorrectInt(currency)) {
			verification.setCurrency(this.commonManager.findEntityByPK(
					Currency.class, Long.parseLong(currency)));
		}
		String employeeId = request.getParameter("employeeId");
		if (CommUtils.isCorrectInt(employeeId)) {
			verification.setEmployee(this.commonManager.findEntityByPK(
					Employee.class, Long.parseLong(employeeId)));
		}
		verification.setCompany(employee.getCompany());

		if (verification != null && verification.getId() != 0) {
			String sumBillMoney = request.getParameter("sumBillMoney");
			if (sumBillMoney == null || "".equals(sumBillMoney))
				sumBillMoney = "0";
			verification.setNotWrittenOffmoney(verification.getMoney()
					- Float.parseFloat(sumBillMoney));
			this.commonManager.modifyEntity(verification);
			ActionUtil.outputData(verification.getId());
		} else {
			// 新增保存
			verification.setNotWrittenOffmoney(verification.getMoney());
			long id = this.commonManager.saveEntity(verification);
			List<VerificationTeam> vtList= getSetVerification(request, verification);
			for (VerificationTeam team : vtList) {
				this.commonManager.saveEntity(team);
			}
			
			ActionUtil.outputData(id);
		}
	}

	//删除收款或付款核销或者奖励核销
	@Action("deleteVerification")
	public void deleteVerification(){
		try{
			List<VerificationTeam> vtList=this.commonManager.findByCustomizedSQL(VerificationTeam.class, " verificationId = "+verification.getId());
			for (VerificationTeam team : vtList) {
				this.commonManager.deleteEntity(team);
			}
			this.commonManager.deleteEntity(verification);
		} catch (Exception e) {
			ActionUtil.outputData(1);
		}
		ActionUtil.outputData(0);
	}
	
	//提交付款核销
	@Action("savePayVerificationBill")
	public void savePayVerificationBill(){
		try {
			HttpServletRequest request = ServletActionContext.getRequest();
			Map<Currency, Float> map = this.excRateManager
					.getAllCurrencyToRMB();
			Verification v = this.commonManager.findEntityByPK(
					Verification.class, verification.getId());
			String workFeeIds = request.getParameter("workFeeIds");
			List<WorkFee> workFeeList = this.commonManager.findByCustomizedSQL(
					WorkFee.class, " id in " + workFeeIds);
			float sumInputMoney = 0;
			for (WorkFee workFee : workFeeList) {
				workManager.updateWorkFeesStatus(workFee.getWork().getId());
				// 用户输入的结算金额
				String inputMoney = request.getParameter("inputMoney_"
						+ workFee.getId());
				// 修改已结算金额
				float writtenOffmoney = workFee.getWrittenOffmoney();
				workFee.setWrittenOffmoney(Float.parseFloat(inputMoney)
						+ writtenOffmoney);
				// 修改未结算金额
				workFee.setNotWrittenOffmoney(workFee.getMoney()
						- workFee.getWrittenOffmoney());

				VerificationBill bill = new VerificationBill();
				bill.setVerification(v);
				bill.setWorkFee(workFee);
				bill.setEmployee(ActionUtil.getSelectEmployee());
				bill.setCurrentWrittenOffMoney(Float.parseFloat(inputMoney));
				if (workFee.getCurrency().getId() == v.getCurrency().getId()) {
					bill.setCurrentWrittenOffMoneyToRate(Float
							.parseFloat(inputMoney));
					if (workFee.getType() == 0) {
						sumInputMoney -= bill.getCurrentWrittenOffMoneyToRate();
					} else if (workFee.getType() == 1) {
						sumInputMoney += bill.getCurrentWrittenOffMoneyToRate();
					}
				} else {
					// 获取当天币种对人民币的汇率
					ExcRate excRate1 = this.excRateManager
							.findByDateAndCurrency(v.getCreateTime(), v
									.getCurrency());
					ExcRate excRate2 = this.excRateManager
							.findByDateAndCurrency(v.getCreateTime(), workFee
									.getCurrency());
					float toRMB1 = 0;
					float toRMB2 = 0;
					if (excRate1 != null) {
						toRMB1 = excRate1.getToRMB();
					} else {
						toRMB1 = map.get(v.getCurrency());
					}
					if (excRate2 != null) {
						toRMB2 = excRate2.getToRMB();
					} else {
						toRMB2 = map.get(workFee.getCurrency());
					}

					float currentWrittenOffMoneyToRate = Float
							.parseFloat(inputMoney)
							* toRMB2 / toRMB1;
					bill
							.setCurrentWrittenOffMoneyToRate(currentWrittenOffMoneyToRate);// 兑换后的价格
					sumInputMoney += bill.getCurrentWrittenOffMoneyToRate();
				}
				workFee.setRewardTime(new Date());
				this.commonManager.modifyEntity(workFee);
				this.commonManager.saveEntity(bill);
			}
			v.setNotWrittenOffmoney(v.getNotWrittenOffmoney() - sumInputMoney);
			this.commonManager.modifyEntity(v);
			ActionUtil.outputData(0);
		} catch (Exception e) {
			ActionUtil.outputData(1);
		}
	}
	
	//撤销付款核销
	@Action("deletePayVerificationBill")
	public void deletePayVerificationBill(){
		try {
			HttpServletRequest request = ServletActionContext.getRequest();
			Verification v = this.commonManager.findEntityByPK(
					Verification.class, verification.getId());
			float sumInputMoney = 0;
			String billIds = request.getParameter("billIds");
			List<VerificationBill> billList = this.commonManager
					.findByCustomizedSQL(VerificationBill.class, " id in "
							+ billIds);
			for (VerificationBill bill : billList) {
				WorkFee workFee = bill.getWorkFee();
				workManager.updateWorkFeesStatus(workFee.getWork().getId());
				// 加上未核销金额
				float notWrittenOffmoney = workFee.getNotWrittenOffmoney();
				workFee.setNotWrittenOffmoney(notWrittenOffmoney
						+ bill.getCurrentWrittenOffMoney());
				// 已核销金额
				float writtenOffmoney = workFee.getWrittenOffmoney();
				workFee.setWrittenOffmoney(writtenOffmoney
						- bill.getCurrentWrittenOffMoney());
				if (workFee.getType() == 0) {
					sumInputMoney -= bill.getCurrentWrittenOffMoneyToRate();
				} else if (workFee.getType() == 1) {
					sumInputMoney += bill.getCurrentWrittenOffMoneyToRate();
				}
				workFee.setRewardTime(null);
				this.commonManager.modifyEntity(workFee);
				this.commonManager.deleteEntity(bill);
			}
			v.setNotWrittenOffmoney(v.getNotWrittenOffmoney() + sumInputMoney);
			this.commonManager.modifyEntity(v);
			ActionUtil.outputData(0);
		} catch (Exception e) {
			ActionUtil.outputData(1);
		}
	}

	//进入收款核销的详情
	@Action("receiveDetail")
	public String receiveDetail(){
		HttpServletRequest request = ServletActionContext.getRequest();
		List<Currency> currencys = ActionUtil.getCompanyParam(null, 0, 0, 0, null);
		request.setAttribute("currencys", currencys);		
		Employee employee = ActionUtil.getSelectEmployee();

		String idStr=request.getParameter("id");
		if(idStr==null || "".equals("idStr")){
			idStr="0";
		}
		
		verification=this.commonManager.findEntityByPK(Verification.class, Long.parseLong(idStr));
		
		if(verification!=null){
			//浏览状态
			List<QueryParam> paramList = new ArrayList<QueryParam>();
			QueryParam param = new QueryParam();
			param.setField(" verificationId = "+verification.getId());
			param.setOp(OP.sql);
			param.setValue(new Object[]{});
			paramList.add(param);
			
			List<QueryOrder> orderList=new ArrayList<QueryOrder>();
			QueryOrder order=new QueryOrder();
			order.setField("id");
			order.setAscOrder(true);
			orderList.add(order);
			
			List<VerificationTeam> vtlist=this.commonManager.findByCustomized(VerificationTeam.class,paramList, orderList);
			
			//控制权限
			String cts_employeecpyid = CookieUtil.getCookieValue(request, "cts_employeecpyid");
			String userId = CookieUtil.getCookieValue(request, "cts_userid");
			if(cts_employeecpyid==null || "".equals(cts_employeecpyid)){
				request.setAttribute("msg", "抱歉!您没有权限查看该订单!");
				return "work/noWorkDetail";
			}
			Employee emp=this.commonManager.findEntityByPK(Employee.class, Long.parseLong(cts_employeecpyid));
			//如果是访客，但不是自己相关的单没有权限查看
			if(emp!=null && emp.getType()==1){
				if(emp.getId()!=verification.getEmployee().getId()){
					request.setAttribute("msg", "抱歉!您没有权限查看该订单!");
					return "work/noWorkDetail";
				}
			}else{
				List<Employee> empList=new ArrayList<Employee>();
				for (VerificationTeam team : vtlist) {
					empList.add(team.getEmployee());
				}
				//没有在作业团队里面，或者不是该订单所属公司的管理员都没有权限查看
				if(!empList.contains(emp) && verification.getCompany().getUser().getId()!=Long.parseLong(userId)){
					request.setAttribute("msg", "抱歉!您没有权限查看该订单!");
					return "work/noWorkDetail";
				}
			}
			request.setAttribute("vtlist", vtlist);
			
			//已结算明细
			billList=this.verificationManager.getVerificationBillByParent(verification.getId());
			float writtenOfmoney=verification.getMoney()-verification.getNotWrittenOffmoney();
			
			float mPercent=writtenOfmoney/verification.getMoney();
			if(mPercent<0){
				mPercent=0;
			}else if(mPercent>1){
				mPercent=1;
			}
			BigDecimal b=new BigDecimal(mPercent);
			mPercent=b.setScale(2,BigDecimal.ROUND_HALF_UP).floatValue();
			request.setAttribute("percent", mPercent);//计算用的百分比（如0.85）
			request.setAttribute("writtenOfmoney", writtenOfmoney);
			//给前台提供所有币种对人民币的汇率
			Map<Currency, Float> map = this.excRateManager.getAllCurrencyToRMB();
			StringBuilder sb = new StringBuilder();
			for(Map.Entry<Currency, Float> entry: map.entrySet()){
				sb.append(entry.getKey().getId() + "," + entry.getValue() + ";");
			}
			request.setAttribute("allCurrencyToRMB", CommUtils.deleteLastChar(sb.toString()));

			int authType=-1;
			//如果不是访客
			if(vtlist!=null && emp.getType()!=1){
				for (VerificationTeam team : vtlist) {
					if(team.getEmployee().getUser().getId()==Long.parseLong(userId)){
						authType=team.getAuth();
						break;
					}
				}
			}
			//如果管理员的公司员工创建的订单，管理员也有权限操作该订单
			if(verification.getCompany().getUser().getId()==Long.parseLong(userId)){
				authType=1;
			}
			request.setAttribute("authType", authType);
			request.setAttribute("emp", emp);
		}else{
			//新增状态
			verification=new Verification();
			List<VerificationTeam> vtlist = this.getSetVerification(request, null);
			if(vtlist==null || vtlist.size()==0){
				request.setAttribute("msg", "该订单不存在！");
				return "work/noWorkDetail";
			}
			request.setAttribute("vtlist", vtlist);
			request.setAttribute("teamData", request.getParameter("teamData"));
			request.setAttribute("newCardNum", this.verificationManager.getNewCardNum(employee.getCompany(), 0));
		}
		
		return "account/receiveDetail";
	}
	
	//查询收款核销可以结算的款项
	@Action("receiveDetailFee")
	public String receiveDetailFee(){
		HttpServletRequest request = ServletActionContext.getRequest();
		List<WorkFee> workFeeList=new ArrayList<WorkFee>();
		Employee employee=new Employee();
		String workCode=request.getParameter("workCode");
		String personId=request.getParameter("personId");
		if(CommUtils.isCorrectInt(personId)){
			employee=this.commonManager.findEntityByPK(Employee.class, Long.parseLong(personId));
		}
		//应收
		String type1=request.getParameter("type1");
		if(type1!=null && ""!=type1){
			List<WorkFee> workFeeList1=verificationManager.getWorkFeeByCondition(employee.getCompany(), employee, Integer.parseInt(type1), workCode,null);
			if(workFeeList1!=null && workFeeList1.size()>0){
				workFeeList.addAll(workFeeList1);
			}
		}
		//代收
		String type2=request.getParameter("type2");
		if(type2!=null && ""!=type2){
			List<WorkFee> workFeeList2=verificationManager.getWorkFeeByCondition(employee.getCompany(), employee, Integer.parseInt(type2), workCode,null);
			if(workFeeList2!=null && workFeeList2.size()>0){
				workFeeList.addAll(workFeeList2);
			}
		}
		//应付
		String type3=request.getParameter("type3");
		if(type3!=null && ""!=type3){
			List<WorkFee> workFeeList3=verificationManager.getWorkFeeByCondition(employee.getCompany(), employee, Integer.parseInt(type3), workCode,null);
			if(workFeeList3!=null && workFeeList3.size()>0){
				workFeeList.addAll(workFeeList3);
			}
		}
		//代付
		String type4=request.getParameter("type4");
		if(type4!=null && ""!=type4){
			List<WorkFee> workFeeList4=verificationManager.getWorkFeeByCondition(employee.getCompany(), employee, Integer.parseInt(type4), workCode,null);
			if(workFeeList4!=null && workFeeList4.size()>0){
				workFeeList.addAll(workFeeList4);
			}
		}
		request.setAttribute("workFeeList", workFeeList);
		return "account/receiveDetailFee";
	}
	
	//新增或修改收款核销
	@Action("saveOrEditReceiveVerification")
	public void saveOrEditReceiveVerification(){
		HttpServletRequest request = ServletActionContext.getRequest();
		Employee employee = ActionUtil.getSelectEmployee();
		String currency = request.getParameter("verification_currency");
		verification.setMoney(verification.getToAccountMoney()+verification.getBankDeductionMoney());
		if(CommUtils.isCorrectInt(currency)){
			verification.setCurrency(this.commonManager.findEntityByPK(Currency.class, Long.parseLong(currency)));
		}
		String employeeId=request.getParameter("employeeId");
		if(CommUtils.isCorrectInt(employeeId)){
			verification.setEmployee(this.commonManager.findEntityByPK(Employee.class, Long.parseLong(employeeId)));
		}
		verification.setCompany(employee.getCompany());
		
		//验证凭证号是否已经存在
		if(this.verificationManager.validateCardNum(verification.getId(),verification.getCompany(), verification.getCardNum(), verification.getType())){
			ActionUtil.outputData(-1);
			return;
		}
		
		if(verification!=null && verification.getId()!=0){
			String sumBillMoney=request.getParameter("sumBillMoney");
			if(sumBillMoney==null || "".equals(sumBillMoney))sumBillMoney="0";
			verification.setNotWrittenOffmoney(verification.getMoney()-Float.parseFloat(sumBillMoney));
			this.commonManager.modifyEntity(verification);
			ActionUtil.outputData(verification.getId());
		}else{
			//新增保存
			verification.setNotWrittenOffmoney(verification.getMoney());
			long id=this.commonManager.saveEntity(verification);
			List<VerificationTeam> vtList= getSetVerification(request, verification);
			for (VerificationTeam team : vtList) {
				System.out.println(team.getAuth());
				this.commonManager.saveEntity(team);
			}
			ActionUtil.outputData(id);
		}
	}
	
	//提交付款核销
	@Action("saveReceiveVerificationBill")
	public void saveReceiveVerificationBill(){
		try {
			HttpServletRequest request = ServletActionContext.getRequest();
			Map<Currency, Float> map = this.excRateManager
					.getAllCurrencyToRMB();
			Verification v = this.commonManager.findEntityByPK(
					Verification.class, verification.getId());
			String workFeeIds = request.getParameter("workFeeIds");
			List<WorkFee> workFeeList = this.commonManager.findByCustomizedSQL(
					WorkFee.class, " id in " + workFeeIds);
			float sumInputMoney = 0;
			for (WorkFee workFee : workFeeList) {
				workManager.updateWorkFeesStatus(workFee.getWork().getId());
				// 用户输入的结算金额
				String inputMoney = request.getParameter("inputMoney_"
						+ workFee.getId());
				// 修改已结算金额
				float writtenOffmoney = workFee.getWrittenOffmoney();
				workFee.setWrittenOffmoney(Float.parseFloat(inputMoney)
						+ writtenOffmoney);
				// 修改未结算金额
				workFee.setNotWrittenOffmoney(workFee.getMoney()
						- workFee.getWrittenOffmoney());

				VerificationBill bill = new VerificationBill();
				bill.setVerification(v);
				bill.setWorkFee(workFee);
				bill.setEmployee(ActionUtil.getSelectEmployee());
				bill.setCurrentWrittenOffMoney(Float.parseFloat(inputMoney));
				if (workFee.getCurrency().getId() == v.getCurrency().getId()) {
					bill.setCurrentWrittenOffMoneyToRate(Float
							.parseFloat(inputMoney));
					if (workFee.getType() == 1) {
						sumInputMoney -= bill.getCurrentWrittenOffMoneyToRate();
					} else if (workFee.getType() == 0) {
						sumInputMoney += bill.getCurrentWrittenOffMoneyToRate();
					}
				} else {
					// 获取当天币种对人民币的汇率
					ExcRate excRate1 = this.excRateManager
							.findByDateAndCurrency(v.getCreateTime(), v
									.getCurrency());
					ExcRate excRate2 = this.excRateManager
							.findByDateAndCurrency(v.getCreateTime(), workFee
									.getCurrency());
					float toRMB1 = 0;
					float toRMB2 = 0;
					if (excRate1 != null) {
						toRMB1 = excRate1.getToRMB();
					} else {
						toRMB1 = map.get(v.getCurrency());
					}
					if (excRate2 != null) {
						toRMB2 = excRate2.getToRMB();
					} else {
						toRMB2 = map.get(workFee.getCurrency());
					}

					float currentWrittenOffMoneyToRate = Float
							.parseFloat(inputMoney)
							* toRMB2 / toRMB1;
					bill
							.setCurrentWrittenOffMoneyToRate(currentWrittenOffMoneyToRate);// 兑换后的价格
					sumInputMoney += bill.getCurrentWrittenOffMoneyToRate();
				}
				workFee.setRewardTime(new Date());
				this.commonManager.modifyEntity(workFee);
				this.commonManager.saveEntity(bill);
			}
			v.setNotWrittenOffmoney(v.getNotWrittenOffmoney() - sumInputMoney);
			this.commonManager.modifyEntity(v);
			ActionUtil.outputData(0);
		} catch (Exception e) {
			ActionUtil.outputData(1);
		}
	}
	
	//撤销收款核销
	@Action("deleteReceiveVerificationBill")
	public void deleteReceiveVerificationBill(){
		try {
			HttpServletRequest request = ServletActionContext.getRequest();
			Verification v = this.commonManager.findEntityByPK(
					Verification.class, verification.getId());
			float sumInputMoney = 0;
			String billIds = request.getParameter("billIds");
			List<VerificationBill> billList = this.commonManager
					.findByCustomizedSQL(VerificationBill.class, " id in "
							+ billIds);
			for (VerificationBill bill : billList) {
				WorkFee workFee = bill.getWorkFee();
				workManager.updateWorkFeesStatus(workFee.getWork().getId());
				// 加上未核销金额
				float notWrittenOffmoney = workFee.getNotWrittenOffmoney();
				workFee.setNotWrittenOffmoney(notWrittenOffmoney
						+ bill.getCurrentWrittenOffMoney());
				// 已核销金额
				float writtenOffmoney = workFee.getWrittenOffmoney();
				workFee.setWrittenOffmoney(writtenOffmoney
						- bill.getCurrentWrittenOffMoney());
				if (workFee.getType() == 1) {
					sumInputMoney -= bill.getCurrentWrittenOffMoneyToRate();
				} else if (workFee.getType() == 0) {
					sumInputMoney += bill.getCurrentWrittenOffMoneyToRate();
				}
				workFee.setRewardTime(null);
				this.commonManager.modifyEntity(workFee);
				this.commonManager.deleteEntity(bill);
			}
			v.setNotWrittenOffmoney(v.getNotWrittenOffmoney() + sumInputMoney);
			this.commonManager.modifyEntity(v);
			ActionUtil.outputData(0);
		} catch (Exception e) {
			ActionUtil.outputData(1);
		}
	}
	
	//进入奖励详情
	@Action("awardDetail")
	public String awardDetail(){
		HttpServletRequest request = ServletActionContext.getRequest();
		List<Currency> currencys = ActionUtil.getCompanyParam(null, 0, 0, 0,
				null);
		request.setAttribute("currencys", currencys);
		Employee employee = ActionUtil.getSelectEmployee();

		String idStr=request.getParameter("id");
		if(idStr==null || "".equals("idStr")){
			idStr="0";
		}
		
		verification=this.commonManager.findEntityByPK(Verification.class, Long.parseLong(idStr));
		
		if(verification!=null){
			// 浏览状态
			List<QueryParam> paramList = new ArrayList<QueryParam>();
			QueryParam param = new QueryParam();
			param.setField(" verificationId = "+verification.getId());
			param.setOp(OP.sql);
			param.setValue(new Object[]{});
			paramList.add(param);
			
			List<QueryOrder> orderList=new ArrayList<QueryOrder>();
			QueryOrder order=new QueryOrder();
			order.setField("id");
			order.setAscOrder(true);
			orderList.add(order);
			
			List<VerificationTeam> vtlist=this.commonManager.findByCustomized(VerificationTeam.class,paramList, orderList);
			
			//控制权限
			String cts_employeecpyid = CookieUtil.getCookieValue(request, "cts_employeecpyid");
			String userId = CookieUtil.getCookieValue(request, "cts_userid");
			if(cts_employeecpyid==null || "".equals(cts_employeecpyid)){
				request.setAttribute("msg", "抱歉!您没有权限查看该订单!");
				return "work/noWorkDetail";
			}
			Employee emp=this.commonManager.findEntityByPK(Employee.class, Long.parseLong(cts_employeecpyid));
			//如果是访客，但不是自己相关的单没有权限查看
			if(emp!=null && emp.getType()==1){
				if(emp.getId()!=verification.getEmployee().getId()){
					request.setAttribute("msg", "抱歉!您没有权限查看该订单!");
					return "work/noWorkDetail";
				}
			}else{
				List<Employee> empList=new ArrayList<Employee>();
				for (VerificationTeam team : vtlist) {
					empList.add(team.getEmployee());
				}
				//没有在作业团队里面，或者不是该订单所属公司的管理员都没有权限查看
				if(!empList.contains(emp) && verification.getCompany().getUser().getId()!=Long.parseLong(userId)){
					request.setAttribute("msg", "抱歉!您没有权限查看该订单!");
					return "work/noWorkDetail";
				}
			}
			request.setAttribute("vtlist", vtlist);
			
			// 已结算明细
			billList = this.verificationManager
					.getVerificationBillByParent(verification.getId());
			float writtenOfmoney = verification.getMoney()
					- verification.getNotWrittenOffmoney();

			float mPercent = writtenOfmoney / verification.getMoney();
			if (mPercent < 0) {
				mPercent = 0;
			} else if (mPercent > 1) {
				mPercent = 1;
			}
			BigDecimal b = new BigDecimal(mPercent);
			mPercent = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
			request.setAttribute("percent", mPercent);// 计算用的百分比（如0.85）
			request.setAttribute("writtenOfmoney", writtenOfmoney);
			// 给前台提供所有币种对人民币的汇率
			Map<Currency, Float> map = this.excRateManager
					.getAllCurrencyToRMB();
			StringBuilder sb = new StringBuilder();
			for (Map.Entry<Currency, Float> entry : map.entrySet()) {
				sb
						.append(entry.getKey().getId() + "," + entry.getValue()
								+ ";");
			}
			request.setAttribute("allCurrencyToRMB", CommUtils
					.deleteLastChar(sb.toString()));
			
			int authType=-1;
			//如果不是访客
			if(vtlist!=null && emp.getType()!=1){
				for (VerificationTeam team : vtlist) {
					if(team.getEmployee().getUser().getId()==Long.parseLong(userId)){
						authType=team.getAuth();
						break;
					}
				}
			}
			//如果管理员的公司员工创建的订单，管理员也有权限操作该订单
			if(verification.getCompany().getUser().getId()==Long.parseLong(userId)){
				authType=1;
			}
			request.setAttribute("authType", authType);
			request.setAttribute("emp", emp);
		} else {
			// 新增状态
			verification = new Verification();
			List<VerificationTeam> vtlist = this.getSetVerification(request,
					null);
			if(vtlist==null || vtlist.size()==0){
				request.setAttribute("msg", "该订单不存在！");
				return "work/noWorkDetail";
			}
			request.setAttribute("vtlist", vtlist);
			request.setAttribute("teamData", request.getParameter("teamData"));
			request.setAttribute("newCardNum", this.verificationManager
					.getNewCardNum(employee.getCompany(), 2));
		}
		return "account/awardDetail";
	}
	
	//查询付款核销可以结算的款项
	@Action("awardDetailFee")
	public String awardDetailFee() {
		HttpServletRequest request = ServletActionContext.getRequest();
		List<WorkFee> workFeeList = new ArrayList<WorkFee>();
		Employee employee = new Employee();
		String workCode = request.getParameter("workCode");
		String personId = request.getParameter("personId");
		if (CommUtils.isCorrectInt(personId)) {
			employee = this.commonManager.findEntityByPK(Employee.class, Long
					.parseLong(personId));
		}
		//奖励的条件（格式为X;X;X）
		String searchTypes=request.getParameter("searchTypes");
		// 奖励：type=5
		List<WorkFee> workFeeList3 = verificationManager
				.getWorkFeeByCondition(employee.getCompany(), employee,
						5, workCode,searchTypes);
		if (workFeeList3 != null && workFeeList3.size() > 0) {
			workFeeList.addAll(workFeeList3);
		}
		
		request.setAttribute("workFeeList", workFeeList);
		return "account/awardDetailFee";
	}

	//新增或修改奖励核销
	@Action("saveOrEditAwardVerification")
	public void saveOrEditAwardVerification(){
		HttpServletRequest request = ServletActionContext.getRequest();
		Employee employee = ActionUtil.getSelectEmployee();
		String currency = request.getParameter("verification_currency");
		verification.setMoney(verification.getToAccountMoney()
				- verification.getBankDeductionMoney());
		if (CommUtils.isCorrectInt(currency)) {
			verification.setCurrency(this.commonManager.findEntityByPK(
					Currency.class, Long.parseLong(currency)));
		}
		String employeeId = request.getParameter("employeeId");
		if (CommUtils.isCorrectInt(employeeId)) {
			verification.setEmployee(this.commonManager.findEntityByPK(
					Employee.class, Long.parseLong(employeeId)));
		}
		verification.setCompany(employee.getCompany());

		if (verification != null && verification.getId() != 0) {
			String sumBillMoney = request.getParameter("sumBillMoney");
			if (sumBillMoney == null || "".equals(sumBillMoney))
				sumBillMoney = "0";
			verification.setNotWrittenOffmoney(verification.getMoney()
					- Float.parseFloat(sumBillMoney));
			this.commonManager.modifyEntity(verification);
			ActionUtil.outputData(verification.getId());
		} else {
			// 新增保存
			verification.setNotWrittenOffmoney(verification.getMoney());
			long id = this.commonManager.saveEntity(verification);
			List<VerificationTeam> vtList= getSetVerification(request, verification);
			for (VerificationTeam team : vtList) {
				this.commonManager.saveEntity(team);
			}
			
			ActionUtil.outputData(id);
		}
	}
	
	//提交奖励核销
	@Action("saveAwardVerificationBill")
	public void saveAwardVerificationBill(){
		try {
			HttpServletRequest request = ServletActionContext.getRequest();
			Map<Currency, Float> map = this.excRateManager
					.getAllCurrencyToRMB();
			Verification v = this.commonManager.findEntityByPK(
					Verification.class, verification.getId());
			String workFeeIds = request.getParameter("workFeeIds");
			List<WorkFee> workFeeList = this.commonManager.findByCustomizedSQL(
					WorkFee.class, " id in " + workFeeIds);
			float sumInputMoney = 0;
			for (WorkFee workFee : workFeeList) {
				workManager.updateWorkFeesStatus(workFee.getWork().getId());
				// 用户输入的结算金额
				String inputMoney = request.getParameter("inputMoney_"
						+ workFee.getId());
				// 修改已结算金额
				float writtenOffmoney = workFee.getWrittenOffmoney();
				workFee.setWrittenOffmoney(Float.parseFloat(inputMoney)
						+ writtenOffmoney);
				// 修改未结算金额
				workFee.setNotWrittenOffmoney(workFee.getMoney()
						- workFee.getWrittenOffmoney());

				VerificationBill bill = new VerificationBill();
				bill.setVerification(v);
				bill.setWorkFee(workFee);
				bill.setEmployee(ActionUtil.getSelectEmployee());
				bill.setCurrentWrittenOffMoney(Float.parseFloat(inputMoney));
				if (workFee.getCurrency().getId() == v.getCurrency().getId()) {
					bill.setCurrentWrittenOffMoneyToRate(Float
							.parseFloat(inputMoney));
					sumInputMoney += bill.getCurrentWrittenOffMoneyToRate();
				} else {
					// 获取当天币种对人民币的汇率
					ExcRate excRate1 = this.excRateManager
							.findByDateAndCurrency(v.getCreateTime(), v
									.getCurrency());
					ExcRate excRate2 = this.excRateManager
							.findByDateAndCurrency(v.getCreateTime(), workFee
									.getCurrency());
					float toRMB1 = 0;
					float toRMB2 = 0;
					if (excRate1 != null) {
						toRMB1 = excRate1.getToRMB();
					} else {
						toRMB1 = map.get(v.getCurrency());
					}
					if (excRate2 != null) {
						toRMB2 = excRate2.getToRMB();
					} else {
						toRMB2 = map.get(workFee.getCurrency());
					}

					float currentWrittenOffMoneyToRate = Float
							.parseFloat(inputMoney)
							* toRMB2 / toRMB1;
					bill
							.setCurrentWrittenOffMoneyToRate(currentWrittenOffMoneyToRate);// 兑换后的价格
					sumInputMoney += bill.getCurrentWrittenOffMoneyToRate();
				}
				workFee.setRewardTime(new Date());
				this.commonManager.modifyEntity(workFee);
				this.commonManager.saveEntity(bill);
			}
			v.setNotWrittenOffmoney(v.getNotWrittenOffmoney() - sumInputMoney);
			this.commonManager.modifyEntity(v);
			ActionUtil.outputData(0);
		} catch (Exception e) {
			ActionUtil.outputData(1);
		}
	}
	
	//撤销奖励核销
	@Action("deleteAwardVerificationBill")
	public void deleteAwardVerificationBill(){
		try {
			HttpServletRequest request = ServletActionContext.getRequest();
			Verification v = this.commonManager.findEntityByPK(
					Verification.class, verification.getId());
			float sumInputMoney = 0;
			String billIds = request.getParameter("billIds");
			List<VerificationBill> billList = this.commonManager
					.findByCustomizedSQL(VerificationBill.class, " id in "
							+ billIds);
			for (VerificationBill bill : billList) {
				WorkFee workFee = bill.getWorkFee();
				workManager.updateWorkFeesStatus(workFee.getWork().getId());
				// 加上未核销金额
				float notWrittenOffmoney = workFee.getNotWrittenOffmoney();
				workFee.setNotWrittenOffmoney(notWrittenOffmoney
						+ bill.getCurrentWrittenOffMoney());
				// 已核销金额
				float writtenOffmoney = workFee.getWrittenOffmoney();
				workFee.setWrittenOffmoney(writtenOffmoney
						- bill.getCurrentWrittenOffMoney());
				sumInputMoney += bill.getCurrentWrittenOffMoneyToRate();
				workFee.setRewardTime(null);
				this.commonManager.modifyEntity(workFee);
				this.commonManager.deleteEntity(bill);
			}
			v.setNotWrittenOffmoney(v.getNotWrittenOffmoney() + sumInputMoney);
			this.commonManager.modifyEntity(v);
			ActionUtil.outputData(0);
		} catch (Exception e) {
			ActionUtil.outputData(1);
		}
	}
	
	//修改是否归档
	@Action("changeVerificationStatus")
	public void changeVerificationStatus(){
		try {
			HttpServletRequest request = ServletActionContext.getRequest();
			String vid=request.getParameter("vid");
			Verification v = this.commonManager.findEntityByPK(Verification.class, Long.parseLong(vid));
			String isSettle=request.getParameter("isSettle");
			if(isSettle==null || "".equals(isSettle)){
				isSettle="0";
			}
			v.setIsSettle(Integer.parseInt(isSettle));
			v.setExchangeMoney(v.getNotWrittenOffmoney());
			this.commonManager.modifyEntity(v);
			ActionUtil.outputData(0);
		} catch (Exception e) {
			ActionUtil.outputData(1);
		}
	}
	
	public Verification getVerification() {
		return verification;
	}

	public void setVerification(Verification verification) {
		this.verification = verification;
	}

	public List<Verification> getVerificationList() {
		return verificationList;
	}

	public void setVerificationList(List<Verification> verificationList) {
		this.verificationList = verificationList;
	}

	public IVerificationManager getVerificationManager() {
		return verificationManager;
	}

	public void setVerificationManager(IVerificationManager verificationManager) {
		this.verificationManager = verificationManager;
	}

	public CommonManager getCommonManager() {
		return commonManager;
	}

	public void setCommonManager(CommonManager commonManager) {
		this.commonManager = commonManager;
	}

	public List<VerificationBill> getBillList() {
		return billList;
	}

	public void setBillList(List<VerificationBill> billList) {
		this.billList = billList;
	}

	public int getPageNumber() {
		return pageNumber;
	}

	public void setPageNumber(int pageNumber) {
		this.pageNumber = pageNumber;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public VerificationBill getVerificationBill() {
		return verificationBill;
	}

	public void setVerificationBill(VerificationBill verificationBill) {
		this.verificationBill = verificationBill;
	}

	public IExcRateManager getExcRateManager() {
		return excRateManager;
	}

	public void setExcRateManager(IExcRateManager excRateManager) {
		this.excRateManager = excRateManager;
	}

	public IWorkManager getWorkManager() {
		return workManager;
	}

	public void setWorkManager(IWorkManager workManager) {
		this.workManager = workManager;
	}

}
